package com.devilvan.betrice.opgg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.opgg.dto.OpggPositionCounterDto;
import com.devilvan.betrice.opgg.po.OpggPositionCounterPo;
import com.devilvan.betrice.opgg.service.OpggPositionCounterService;
import com.devilvan.betrice.opgg.mapper.OpggPositionCounterMapper;
import com.devilvan.betrice.opgg.repository.OpggPositionCounterRepository;
import com.devilvan.betrice.util.UCopy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Evad.Wu
 * @Description OPGG-英雄位置-英雄克制信息 业务逻辑类
 * @date 2022-10-04
 */
@Service
public class OpggPositionCounterServiceImpl extends ServiceImpl<OpggPositionCounterMapper, OpggPositionCounterPo> implements OpggPositionCounterService {
    @Resource(name = "opggPositionCounterRepository")
    private OpggPositionCounterRepository opggPositionCounterRepository;

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public OpggPositionCounterPo saveUpdate(OpggPositionCounterDto opggPositionCounterDto) {
        OpggPositionCounterPo opggPositionCounterPo = new OpggPositionCounterPo();
        UCopy.fullCopy(opggPositionCounterDto, opggPositionCounterPo);
        return opggPositionCounterRepository.saveAndFlush(opggPositionCounterPo);
    }

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public List<OpggPositionCounterPo> saveUpdateBatch(List<OpggPositionCounterDto> list) {
        List<OpggPositionCounterPo> opggPositionCounterPoList = UCopy.fullCopyCollections(list, OpggPositionCounterPo.class);
        return opggPositionCounterRepository.saveAllAndFlush(opggPositionCounterPoList);
    }
}
